using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace RGBHand.Sample.Typing
{
    public class ButtonComponent : MonoBehaviour
    {
        public SampleKeyPad keyPad;

        public FPButton button;

        public Text text;

        private void Awake()
        {
            keyPad = GetComponentInParent<SampleKeyPad>();
            text = GetComponentInChildren<Text>();
            button = GetComponent<FPButton>();
        }

        // Start is called before the first frame update
        void Start()
        {
            var selfName = gameObject.name;
            var typeChars = selfName.ToCharArray();
            char lastChar = typeChars[typeChars.Length - 1];
            if (lastChar >= 65 && lastChar <= 90)
            {
                button.onClick.AddListener(() => keyPad.OnBtnInput(lastChar));
                text.text = lastChar + "";
            }
            else if (lastChar >= 48 && lastChar <= 57)
            {
                button.onClick.AddListener(() => keyPad.OnBtnInput(lastChar - 48));
                text.text = (lastChar - 48) + "";
            }
        }
    }
}
